//
//  BKMyOrderWebViewController.m
//  bestkeep
//
//  Created by mac on 16/12/18.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKMyOrderWebViewController.h"
#import "Masonry.h"
#import "NJKWebViewProgressView.h"
#import "NJKWebViewProgress.h"
@interface BKMyOrderWebViewController ()<NJKWebViewProgressDelegate,UIWebViewDelegate>
{
    NJKWebViewProgressView *_progressView;
    NJKWebViewProgress *_progressProxy;
}
@property (nonatomic, strong) UIWebView *webView;

@end

@implementation BKMyOrderWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = self.webViewTitle;
    
    [self loadWebView];
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    _progressView.hidden=YES;
}
-(void)loadWebView{
    _progressProxy = [[NJKWebViewProgress alloc] init];
    _progressProxy.webViewProxyDelegate = self;
    _progressProxy.progressDelegate = self;
    NSURL *url =[NSURL URLWithString:_webViewUrl];
    NSURLRequest *request =[NSURLRequest requestWithURL:url];
    
    self.webView = [[UIWebView alloc] initWithFrame:CGRectZero];
    [self.view addSubview:self.webView];
    
    //    self.webView.delegate = self;
    _webView.delegate= _progressProxy;
    [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view. mas_left).offset(0);
        make.top.equalTo(self.view.mas_top).mas_offset(0);
        make.right.equalTo(self.view. mas_right).offset(0);
        make.bottom.equalTo(self.view.mas_bottom).mas_offset(0);
    }];
    
    CGRect navBounds = self.navigationController.navigationBar.bounds;
    CGRect barFrame = CGRectMake(0,
                                 navBounds.size.height - 2,
                                 navBounds.size.width,
                                 2);
    _progressView = [[NJKWebViewProgressView alloc] initWithFrame:barFrame];
    _progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
    [_progressView setProgress:0 animated:YES];
    [self.navigationController.navigationBar addSubview:_progressView];
    [self.webView loadRequest:request];
    
    for (UIView *_aView in [self.webView subviews])
    {
        if ([_aView isKindOfClass:[UIScrollView class]])
        {
            [(UIScrollView *)_aView setShowsVerticalScrollIndicator:NO];
            //右侧的滚动条
        }
    }
    
    self.webView.scrollView.bounces = NO;
}
#pragma mark - NJKWebViewProgressDelegate
-(void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
{
    [_progressView setProgress:progress animated:YES];
    if (!self.title) {
        self.title = [_webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    }
    
}
@end
